package com.itheima.controller;

import com.itheima.entity.Result;
import com.itheima.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IndexService indexService;

    /**
     * 获取一年内每天的文章贡献度
     * @return
     */
    @GetMapping("/getBlogContributeCount")
    public Result getBlogContributeCount(){
        Map resultMap = indexService.getBlogContributeCount();
        return new Result("success",resultMap);
    }

    /**
     * 获取每个分类下文章数目
     * @return
     */
    @GetMapping("/getBlogCountByBlogSort")
    public Result getBlogCountByBlogSort(){
        List<Map> list = indexService.getBlogCountByBlogSort();
        return new Result("success",list);
    }

    /**
     * 获取每个标签下文章数目
     * @return
     */
    @GetMapping("/getBlogCountByTag")
    public Result getBlogCountByTag(){
        List<Map> list = indexService.getBlogCountByTag();
        return new Result("success",list);
    }

    /**
     * 获取最近一周用户独立IP数和访问量
     */
    @GetMapping("/getVisitByWeek")
    public Result getVisitByWeek(){
        Map<String, List> resultMap = indexService.getVisitByWeek();
        return new Result("success",resultMap);
    }

    /**
     * 获取最近一周用户独立IP数和访问量
     */
    @GetMapping("/init")
    public Result init(){
        Map<String, Integer> resultMap = indexService.init();
        return new Result("success",resultMap);
    }
}
